3. Special Characters, Line Breaks, and Multi-Line Equations
Special Characters
The backslash key \
is used to tell to expect a command. There are other special keys too—for instance, $
tells to expect maths. But what if you actually want to type a dollar sign? The trick is to type \$
. In this case the \
tells
to treat the dollar sign as a normal character, rather than as a math
mode entry command. This idea works with all special characters, apart
from with the backslash itself.
There are ten special characters in total. Here they are:
Special character | What does it do? | How to print it |
---|---|---|
\ |
Starts a command | \textbackslash |
$ |
Enters/exits math mode | \$ |
% |
Comment | \% |
^ |
Superscript | \^ |
_ |
Subscript | \_ |
{ and } |
Surrounds characters | \{ and \} |
& |
Used in multi-line equations | \& |
~ |
Unbreakable space | \~ |
# |
Used when defining macros | \# |
We have already met most of these, but let us clarify a few more important points:
- The backslash key is the exception. You cannot print a backslash by typing
\\
. This is because\\
instead tells to start a new paragraph. More on this below. - The
%
sign tells to ignore the rest of the current line. This is best used at the start of a line to mark that line as a “comment”. - The
{
and}
characters are used to surround multiple characters that should treat as a single character. This is mainly used inside math mode in tandem with superscripts and subscripts. Surrounding a single character with{
and}
has no effect: both$x^{2}$
and$x^2$
print .
Of the three remaining special characters, &
and ~
will be discussed today. We will come back to #
in a few lecture's time when we discussing creating macros.
Line Breaks and Spacing
usually decides by itself where to put line breaks. It's mostly pretty good, but it sometimes gets it wrong. The ~
command is used to tell it may not make a line break at this space.
This is useful when writing people's initials. For instance, in the following document, the linebreak after the first “R.” in “George R. R. Martin” is confusing:

So to fix this we can replace the spaces with unbreakable spaces:
Unfortunately this has the undesirable effect that “Martin” is now hyphenated:

When faced with a problem like this, usually the best thing to do is simply to rewrite your sentence slightly:

If you are feeling really stubborn however, there are several other things you can try:
- The command
\linebreak
tells it must break a line here. - The command
\nolinebreak
tells it may not break a line here. - As a last resort, you can surround text that you don't want to be broken up inside an invisible box, like this:
\mbox{George R. R. Martin}
. This will prevent from breaking up the expression “George R. R. Martin” at all. Warning: This will often mess up the spacing and cause things to stick out into the margin. Not recommended unless you're desperate.
There are several ways to start a new line in :
- Leave a blank line. We already saw this last lecture. This also starts a new paragraph (i.e. the next line is indented).
- Use the
\\
command. This also starts a new paragraph (i.e. the next line is indented). - Use the
\newline
command. This does not start a new paragraph (i.e. the next line is not indented). - Use the two commands
\hfill
and\break
. The command\hfill
inserts as much horizontal space as it can (in this case, until the end of the line). Then\break
ends the current line. This does not start a new paragraph (i.e. the next line is not indented). - If
you want to leave an entire blank line between two paragraphs you can
combine these commands. For instance, ending a paragraph with
\\
and then leaving a blank line results in an empty line between paragraphs. - Alternatively you can use the
\vspace{}
command to leave vertical space. The amount of space you leave is dictated by what value you give it. For instance,\vspace{2cm}
leaves a 2cm gap. The command\hspace{}
works in the same way, only it leaves a horizontal space.
Here are some of these commands in action:

The \vspace{}
command allows for finer control, but it requires a specific length to be inputted. There are seven different units that understands. They are:
Unit | Meaning |
---|---|
mm | millimetre |
cm | centimetre |
in | inch |
pt | a “point” (≈ 1/3 mm) |
ex | ≈ the height of an “x” |
em | ≈ the width of an “M” |
mu | 1/18 of an em |
Multi-Line Equations and Matrices
Not all equations are as short and snappy as . Sometimes the equation you wish to type is too long to fit on a single line, and you need to split it onto multiple lines. Alternatively, sometimes you might want to display several lines of working.
The amsmath
package we discussed last time allows for such advanced wizardry. It
offers several different solutions, the most useful of which are align
and multiline
.

The salient points are:
- The
\begin{align} ... \end{align}
commands replaces the\begin{equation} ... \end{equation}
commands. - The
\\
starts a new line of the equation. - The
&
character tells how to align the equations. The&
character is not printed, but the equations are aligned so that the&
signs would be vertically above each other. - Each line of the
align
environment is numbered. To later reference a line, add a\label
command to that particular line. If you don't want a particular line to have a number, you can add\nonumber
to that line. Alternatively, if you don't want any of the equations to be numbered, use the command\begin{align*} ... \end{align*}
.
Here is a more complex example.

Note in this case there are two &
signs on each line, and only the third equation is numbered.
If you only have one equation, but it is too long to fit on one line, use multiline
instead.

In this example we also used some common operators: \sin
, \cos
, \exp
and \sqrt{}
.
Another useful amsmath
command is the cases
environment. Here is an example.

- Unlike the
align
command, thecases
environment does not replace the display math environment, but rather goes it. - The syntax is similar to
align
: the&
character indicates how the equations should be aligned. The\\
command starts a new line. - Note in this example we also need the
amssymb
package because of the .
- We used the command
\colon
when specifying the domain and range of the functions and . It is not enough to just write a normal colon
Finally, let us briefly discuss matrices, since the syntax is again similar.
Try it for yourself—there is a difference. (Okay, perhaps I am being a little pedantic here...) ↩︎

- The
pmatrix
environment produces a matrix with round brackets. If you want one with square brackets, usebmatrix
instead. - The
&
sign is used to separate the cells. The\\
starts a new line. - You don't need to specify the size of the matrix— will work it out automatically by how many
&
and\\
you use. It will throw an error, however, if your first row has four entries and the second row has twelve. - Fun Fact: The computation of was the “amazing” problem that Matt Damon solved in the movie Good Will Hunting.
